package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

public class Mobile2030606174MZQ0408 extends AppCompatActivity {
    CheckBox checkBox_one;
    CheckBox checkBox_two;
    CheckBox checkBox_there;
    TextView text_one;
    TextView text_two;
    Button button_one;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        inOnvk();


        checkBox_one.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    text_two.setText("选中："+buttonView.getText().toString());
                }else{
                    text_two.setText("取消选中："+buttonView.getText().toString());
                }
            }
        });

        checkBox_two.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    text_two.setText("选中："+buttonView.getText().toString());
                }else{
                    text_two.setText("取消选中："+buttonView.getText().toString());
                }
            }
        });

        checkBox_there.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    text_two.setText("选中："+buttonView.getText().toString());
                }else{
                    text_two.setText("取消选中："+buttonView.getText().toString());
                }
            }
        });

        button_one.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String msg = "选中:";
              if (checkBox_one.isChecked()){
                  msg += '\n'+checkBox_one.getText().toString();
              }

              if (checkBox_two.isChecked()){
                  msg += '\n'+checkBox_two.getText().toString();
              }

              if (checkBox_there.isChecked()){
                  msg += '\n'+checkBox_there.getText().toString();
              }

              text_two.setText(msg);



          }
      });






    }
    private void inOnvk(){
        checkBox_one = findViewById(R.id.checkBox_one);
        checkBox_two = findViewById(R.id.checkBox_two);
        checkBox_there = findViewById(R.id.checkBox_there);
        button_one = findViewById(R.id.button);
        text_one = findViewById(R.id.textView_one);
        text_two = findViewById(R.id.textView_two);
    }
}